<%@page import="transfer.Address"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@page import="transfer.Commodity"%>
<%@page import="content.CommodityContent"%>
<%@page import="transfer.Comment"%>
<%@page import="transfer.Order"%>
<%@page import="content.OrderContent"%>
<%@page import="java.util.ArrayList"%>
<div class="block-header" id="id_order" value="<%=request.getParameter("id")%>" >Order #<%=request.getParameter("id")%></div>
<div class="box">
    <table class="table" rules=all>
        <tr>
            <td>Date</td>
            <td>State</td>
            <td>User name</td>
            <td>Comment</td>
        </tr>
        <%
            Order order = OrderContent.getOrder(new Integer(request.getParameter("id")));
            ArrayList commentList = OrderContent.getAllCommentsForOrder(order);
            HashMap goodsList = order.getCommodities();
            Iterator iterator = goodsList.keySet().iterator();
            for (int j = 0; j < commentList.size(); j++) { 
                Comment comment = (Comment)commentList.get(j);
        %>
        <tr>
            <td><%=comment.getCommentDate()%></td>
            <td><%=comment.getOrderState().getNameOrderState()%></td>
            <td>
                <%
                    if (comment.getUser() != null) {
                        out.print(comment.getUser().getFirstName()+" "+comment.getUser().getLastName());
                    } else {
                        out.print("Anonymous customer");
                    }
                %>
            </td>
            <td><%=comment.getCommentText()%></td>
        </tr>
        <%
            }
        %>
    </table>
</div>
<br/>
<table id="cart-table" border="0" rules=rows bordercolor="#efefef">
    <tr>
        <td width="100px">Items</td>
        <td></td>
        <td width="60px">Quantity</td>
        <td width="120px"  style="text-align: right;">Price</td>
    </tr>
    <%
    
        while(iterator.hasNext()) {
            Object key = iterator.next();
    %>
    <tr>
        <td><a href="../index.jsp?content=view" target="_blank"><img src="../images/commodity/<%=((Commodity)key).getImage()%>"></a></td>
        <td><a href="../index.jsp?content=view" target="_blank"><%=((Commodity)key).getNameCommodity()%></a></td>
        <td><%=goodsList.get(key)%></td>
        <td style="text-align: right;"><b><%=((Commodity)key).getPrice()+" $"%></b></td>
    </tr>
    <%  
        }
    %>
</table>
<div style="width: 854px; text-align: right; font-size: 16px; font-weight: bold; margin: 5px 0px 5px 0px; padding-top: 15px;">
    <span style="margin-right: 70px;">Total:</span><%=order.getCostCommodities()%>
</div>
<div class="table-view">
    <div>Current state:</div><%=order.getOrderState().getNameOrderState()%><br/>
    <div>Customer name:</div><%= order.getCustomer() == null ? "Anonymous customer" :
            order.getCustomer().getFirstName() + " " + order.getCustomer().getLastName() %><br/>
    <div>Location:</div><%= order.getAddress() != null ? order.getAddress() : order.getCustomer().getAddress()%><br/>
    <div>Distance:</div><%=order.getDistance()%><br/>
    <div>Shipment price:</div><%=order.getCostDelivery()+ " $"%><br/>
    <div>Total price:</div><%=order.getTotalCost()+ " $"%><br/>    
</div>

<h3>Comment</h3>
<textarea id="comment" maxlength="1000"></textarea>